package com.weasing.res.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.weasing.res.dao.IWxEvalresultDao;
import com.weasing.res.dao.base.impl.BaseDaoImpl;
import com.weasing.res.domain.WxEvalresult;

@Repository
public class WxEvalresultDaoImpl extends BaseDaoImpl<WxEvalresult> implements
		IWxEvalresultDao {

	@Override
	public WxEvalresult findByUdetailid(Integer udetailid) {
		WxEvalresult wx = new WxEvalresult();

		String hql = "FROM WxEvalresult e where e.udetailid = " + udetailid;
		List<WxEvalresult> find = (List<WxEvalresult>) this
				.getHibernateTemplate().find(hql);
		if (find.size() > 0) {
			wx = find.get(0);
		}
		return wx;
	}

	@Override
	public Integer jiyaCount() {

		String hql = "select count(*)  from WxEvalresult w where w.totalscore > -6";
		Session session = this.getSessionFactory().getCurrentSession();
		Query query = session.createQuery(hql);
		Integer i = ((Long) query.iterate().next()).intValue();
		return i;
	}

	@Override
	public Integer nojiyaCount() {

		String hql = "select count(*)  from WxEvalresult w where w.totalscore <= -6";
		Session session = this.getSessionFactory().getCurrentSession();
		Query query = session.createQuery(hql);
		Integer i = ((Long) query.iterate().next()).intValue();
		return i;
	}

}
